<template>
  <a-modal :title="`编辑奖品等级`" style="top: 100px;" :visible="true" width="1000px" @cancel="handleCancel">
    <a-table class="product-table" :rowKey="row => row.id" :dataSource="list" bordered :pagination="false" size="small">
      <a-table-column title="序号" width="20px">
        <template slot-scope="text, record, index">
          <div>{{ index+1 }}</div>
        </template>
      </a-table-column>
      <a-table-column title="标题" key="thumb" width="80px">
        <template slot-scope="row">
          <a-input v-model="row.title" placeholder="留空则使用默认设置"></a-input>
        </template>
      </a-table-column>
      <a-table-column title="充能" key="charge" width="80px">
        <template slot-scope="row">
          <a-input-number v-model="row.charge" style="width: 100px;"></a-input-number> 次
        </template>
      </a-table-column>
      <a-table-column title="上下架" width="80px">
        <template slot-scope="row">
          <span>
            <i-switch :active="row.status || 1" v-model="row.status" size="small"></i-switch>
          </span>

        </template>
      </a-table-column>
    </a-table>
    <template slot="footer">
      <div class="btn-c">
        <!-- <a-button type="primary" class="add" @click="handleCreate">
          新增一款
        </a-button> -->
        <div style="flex-grow: 1;"></div>

        <!-- <a-button key="back" @click="handleCancel">关闭</a-button> -->
        <a-button key="submit" type="primary" @click="handleSave">
          保存并关闭
        </a-button>
      </div>
    </template>
  </a-modal>
</template>
<script>
  import iSwitch from '@/components/ISwitch/ISwitch'
  export default {
    components: {
      iSwitch
    },
    props: {
      uuid: {
        type: String,
        default () {
          return ''
        }
      },
      info: {
        type: Object
      }
    },
    data() {
      return {
        list: [],
      }
    },
    watch: {
    },
    created() {
      this.list = JSON.parse(JSON.stringify(this.info.word_level)).slice(0, 5)
      // this.initList()
    },
    methods: {
      handleCancel() {
        this.$emit('refresh')
        this.$emit('close')
      },
      handleSave() {
        let status = 0;
        for (let i = 0; i < this.list.length; i++) {
          if (this.list[i].status == 1) {
            status = 1;
          }
        }
        if (status != 1) {
          this.$message.error('必须有一个世界存在')
          return false
        }

        this.$http.put(`/maoxians/${this.info.uuid}/word-level`, {
          list: this.list
        }).then(res => {
          this.$message.success('保存成功')
          // this.initList()
          this.$emit('refresh')
          this.$emit('close')
        })
      },
    }
  }
</script>
<style lang="less" scoped>
  .thumb {
    width: 60px;
    height: 60px;
    border-radius: 6px;
  }
  .btn-c {
    display: flex;
    // margin-top: 30px;
    padding: 0rpx 30rpx;

    .add {}

    .save {
      margin-right: 20px;
    }

    .cancel {}
  }

  .tips {
    color: gray;
    font-size: 80%;
    margin-bottom: 10px;
  }

  a-input {
    display: inline;
  }
</style>
